<div class="container-fluid">
    <div class="wrapper">
        <div class="panel" id="nav">
            <div class="panel-heading"><h3 class="panel-title">供应商送货单图片录入</h3></div>
            <div class="panel-body">

                <form action="" method="get">
                    <div class="container-fluid">
                        <div class="col-sm-12 col-md-3  add-space">
                            <div class="input-group input-group-md">
                                <span class="input-group-addon">采购单号</span>
                                <input type="text" name="purchase_id" class="form-control" value="">
                            </div>
                        </div>

                        <div class="col-sm-12 col-md-3  add-space">
                            <div class="input-group input-group-md">
                                <span class="input-group-addon">收货单号</span>
                                <input class="form-control" type="text" name="recieve_invoices" >
                            </div>
                            <span id="tip" style="margin-left: 100px;"></span>
                        </div>

                        <div class="col-sm-12 col-md-3  add-space">
                            <div class="input-group input-group-md">
                                <span class="input-group-addon">收货人</span>
                                <input type="text" name="reciever_id" class="form-control" value="">
                            </div>
                        </div>

                        <div class="col-sm-12 col-md-3  add-space">
                            <div class="input-group input-group-md">
                                <span class="input-group-addon">收货时间</span>
                                <input class="form-control form-datetime" type="text" name="recieve_time_from"
                                       style="cursor:pointer;" readonly>
                                <span class="input-group-addon"><span class="icon-calendar"></span></span>
                                <input class="form-control form-datetime" type="text" name="recieve_time_to"
                                       style="cursor:pointer;" readonly>
                            </div>
                        </div>

                        <div class="col-sm-12 col-md-3  add-space">
                            <div class="input-group input-group-md">
                                <span class="input-group-addon">上传人</span>
                                <input type="text" name="uploader_id" class="form-control" value="">
                            </div>
                        </div>

                        <div class="col-sm-12 col-md-3  add-space">
                            <div class="input-group input-group-md">
                                <span class="input-group-addon">上传时间</span>
                                <input class="form-control form-datetime" type="text" name="upload_time_from"
                                       style="cursor:pointer;" readonly>
                                <span class="input-group-addon"><span class="icon-calendar"></span></span>
                                <input class="form-control form-datetime" type="text" name="upload_time_to"
                                       style="cursor:pointer;" readonly>
                            </div>
                        </div>

                        <div class="col-md-2 add-space">
                            <input class="btn btn-primary" type="button" onclick="select_recieveinfo()" value="查询">
                            <input class="btn btn-primary" type="button" onclick="resetSelectInfo()" value="重置">
                        </div>
                    </div>
                </form>
                <div class="detail_content">
                    <table class="table table-striped  table-hover" cellspacing="0" width="100%">
                        <thead>
                        <tr>
                            <th>采购单号</th>
                            <th>收获单号</th>
                            <th>收货人</th>
                            <th>收货时间</th>
                            <th>送货单展示</th>
                            <th>操作</th>
                        </tr>
                        </thead>
                        <tbody id="recieve_pictureinfo">

                        </tbody>
                    </table>
                </div>
                <div class="clearfix"></div>
                <div class="clearfix clear"></div>
                <div class="row">
                    <div class="col-md-6 pull-left">
                        <label>每页 20 条记录
                            显示 1 到 20 项，共 {$count}项</label>
                    </div>
                    <div class="col-md-6">
                        <div class="page pull-right" style="padding: 0;margin: 0">
                            {$page}
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<script type="text/javascript" src="__PUBLIC__/javascripts/admin/layer/layer.js"></script>
<script type="text/javascript"  src="__PUBLIC__/javascripts/admin/zxxFile.js"></script>

<script>
    $(function () {
        $("input[name='purchaseid']").val("<?php echo $_GET['purchaseid'];?>");
    });
    function resetSelectInfo(){
        $("input[name='purchase_id']").val('');
        $("input[name='recieve_invoices']").val('');
        $("input[name='reciever']").val('');
        $("input[name='recieve_time_from']").val('');
        $("input[name='recieve_time_to']").val('');
        $("input[name='uploader']").val('');
        $("input[name='upload_time_from']").val('');
        $("input[name='upload_time_to']").val('');
    }

    /**
     * 根据采购单号获取采购单信息
     */
    function select_recieveinfo() {
        var purchase_id = $("input[name='purchase_id']").val();
        var recieve_invoices = $("input[name='recieve_invoices']").val();
        var reciever_id = $("input[name='reciever_id']").val();
        var recieve_time_from = $("input[name='recieve_time_from']").val();
        var recieve_time_to = $("input[name='recieve_time_to']").val();
        var uploader_id = $("input[name='uploader_id']").val();
        var upload_time_from = $("input[name='upload_time_from']").val();
        var upload_time_to = $("input[name='upload_time_to']").val();
        if (purchase_id||recieve_invoices||reciever_id||recieve_time_from||recieve_time_to||uploader_id||upload_time_from||upload_time_to) {
            $.ajax({
                type: "get",
                async: true,
                data: {
                    'purchase_id': purchase_id,
                    'recieve_invoices': recieve_invoices,
                    'reciever_id': reciever_id,
                    'recieve_time_from': recieve_time_from,
                    'recieve_time_to': recieve_time_to,
                    'uploader_id': uploader_id,
                    'upload_time_from': upload_time_from,
                    'upload_time_to': upload_time_to
                },//采购单表id
                url: "{:U('Purchaseorders/select_recievepicinfo')}",
                dataType: "json",
                success: function (data) {
                    if (data.flag == -1) {
                        layer.msg('查询结果为空！');
                        $("#recieve_pictureinfo").html('');
                        return;
                    } else if (data.flag == 1) {
                        var html = '';
                        $.each(data.info, function (n, data) {
                            var string='';
                            if(data.details){
                                for(detail in data.details){
                                    string+='<div style="width: 100px; float: left; padding:4px;margin: 4px; border: 1px solid #ccc; text-align: center;">' +
                                            '<img src="__ROOT__/'+data.details[detail].url+'"  class="image" onclick="showThis(this)"/>' +
                                            '</br><a>'+data.details[detail].uploader+
                                            '</br><a>'+data.details[detail].upload_time+'</a><br />'+
                                            '</br><a title="删除" id="'+data.details[detail].url+'"onclick="delPic(this)">删除</a><br /></div>';
                                }
                            }
                            html += "<tr>" +
                                    '<td>' + data.purchase_id + '</td>' +
                                    '<td>' + data.recieve_invoice_id + '</td>' +
                                    '<td>' + data.reciever + '</td>' +
                                    '<td>' + data.recieve_time + '</td>' +
                                    '<td>' + string + '</td>'+
                                    '<td>' + '<input type="button" value="上传" onclick="addPic('+data.id+')">'
                            '</tr>';
                        });
                        $("#recieve_pictureinfo").html(html);
                    }
                }
            });
        } else {
            layer.msg('请选择查询条件！');
            return;
        }
    }

    function addPic(id) {
        //        alert("__URL__");return;
        layer.open({
            title: '上传送货单图片',
            type: 2,
            shadeClose: true, //点击遮罩关闭层
            skin: 'layui-layer-rim', //加上边框
            area: ['60%', '90%'], //宽高
            content: '__URL__/multiupload_imgs?id='+id,
        });
    }
    /**
     * 点击放大
     */
    function showThis (obj) {
        var src = $(obj).attr('src');
        layer.open({
            title:'',
            type: 1,
            area: ['1200px', '720px'],
            content: '<img src="'+src+'" width>',
        });

    }

    /**
     * 删除图片
     */
    function delPic(obj){
        var picurl=obj.id;
        if(confirm("删除后无法恢复，确定要删除该条记录吗?")){
            $.ajax({
                type: "get",
                async: true,
                data: {'picurl': picurl},
                url: "{:U('Purchaseorders/delPic')}",
                success: function (data) {
                    if(data){
                        alert('删除成功！');
                        select_recieveinfo();
                    }else{
                        alert('删除失败！');
                        select_recieveinfo();
                    }
                }
            });
        }else{
            return false;
        }
    }

</script>

